package com.hospital.hospitalserver.controller;

import com.hospital.hospitalserver.entity.DiagnosisRecordDTO;
import com.hospital.hospitalserver.entity.DoctorDetail;
import com.hospital.hospitalserver.entity.ExamOrderRequest;
import com.hospital.hospitalserver.entity.PatientVisitDTO;
import com.hospital.hospitalserver.entity.query.*;
import com.hospital.hospitalserver.service.*;
import com.hospital.hospitalserver.util.Pager;
import com.hospital.hospitalserver.util.Response;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 医生功能API接口
 * */
@CrossOrigin
@RestController
@RequestMapping("/doctor")
@RequiredArgsConstructor
public class DoctorController {
    private final DoctorService doctorService;
    private final ProfessionService professionService;
    private final DoctorVisitService doctorVisitService;
    private final PatientVisitService patientVisitService;
    private final DiagnosisRecordService diagnosisRecordService;
    private final PatientMasterService patientMasterService;
    private final ExamOrderService examOrderService;

    /**
     * 新增医生
     * */
    @PostMapping("/addDoctor")
    public Response addDoctor(@RequestBody DoctorDetail doctor){
        return doctorService.addDoctor(doctor);
    }

    /**
     * 编辑医生信息
     * */
    @PostMapping("/editDoctor")
    public Response editDoctor(@RequestBody DoctorDetail doctor){
        return doctorService.editDoctor(doctor);
    }

    /**
     * 获取医生职称信息列表
     * */
    @GetMapping("/getDoctorProfessionList")
    public Response getDoctorProfessionList(){
        return professionService.getDoctorProfessionList();
    }

    /**
     * 分页功能
     * 装载医生分页数据信息给前端API
     * */
    @PostMapping("/getDoctorPagerDataBySearch")
    public Response getDoctorPagerDataBySearch(@RequestBody Pager pager){
        return doctorService.getDoctorPagerDataBySearch(pager);
    }

    /**
     * 获取医生的列表数据
     * 用于查询检索
     * */
    @GetMapping("/getDoctorList")
    public Response getDoctorList(){
        return doctorService.getDoctorList();
    }

    /**
     * 获取医生当天患者列表
     */
    @PostMapping("/getTodayPatientList")
    public Response getTodayPatientList(@RequestBody DoctorPatientQuery query){
        return doctorVisitService.getTodayPatientList(query);
    }

    /**
     * 更新患者就诊状态
     * 就诊中
     * */
    @PostMapping("/updatePatientStatus")
    public Response updatePatientStatus(@RequestBody DoctorPatientQuery query){
        return Response.success();
    }

    /**
     * 医生工作台
     * 获取当前医生的月视图-周视图-日视图的排班数据
     * */
    @PostMapping("/queryDoctorScheduleInstanceData")
    public Response queryDoctorScheduleInstanceData(@RequestBody DoctorScheduleQuery query){
        return doctorService.queryDoctorScheduleInstanceData(query);
    }

    /**
     * 装载分页数据传给前端API
     * */
    @PostMapping("/getDoctorReservationList")
    public Response getDoctorReservationList(@RequestBody DoctorPatientQuery query){
        return patientVisitService.getPatientVisitDataBySearch(query);
    }

    /**
     * 医生开始就诊时
     * 更新患者状态
     * */
    @PostMapping("/updatePatientVisitStatus")
    public Response updatePatientVisitStatus(@RequestBody PatientVisitDTO request){
        return patientVisitService.updatePatientVisitStatus(request);
    }

    /**
     * 医生开始诊断
     * 查找就诊记录
     * */
    @PostMapping("/getDiagnosisRecordByVisitId")
    public Response getDiagnosisRecordByVisitId(@RequestBody DiagnosisRecordDTO request){
        return diagnosisRecordService.selectByVisitId(request);
    }

    /**
     * 医生保存诊断记录
     * */
    @PostMapping("/saveDiagnosisRecord")
    public Response saveDiagnosisRecord(@RequestBody DiagnosisRecordDTO request){
        return diagnosisRecordService.saveDiagnosisRecord(request);
    }

    /**
     * 医生工作台端
     * 装载患者档案数据分页
     * */
    @PostMapping("/getPatientMasterPagerDataByDoctorSearch")
    public Response getPatientMasterPagerDataByDoctorSearch(@RequestBody DoctorPatientMasterQuery query){
        return patientMasterService.getPatientMasterPagerDataByDoctorSearch(query);
    }

    /**
     * 医生工作台
     * 患者预约挂号管理
     * 根据预约挂号id查询，当前患者详细的诊断记录
     * */
    @PostMapping("/getDiagnosisRecordDetailByVisitId")
    public Response getDiagnosisRecordDetailByVisitId(@RequestBody DiagnosisRecordDTO dto){
        return diagnosisRecordService.getDiagnosisRecordDetailByVisitId(dto);
    }

    /**
     * 医生工作台
     * 患者预约挂号管理
     * 根据记录id查询当前患者详细的诊断记录
     * */
    @PostMapping("/getDiagnosisRecordDetailByRecordNo")
    public Response getDiagnosisRecordDetailByRecordNo(@RequestBody DiagnosisRecordDTO dto){
        return diagnosisRecordService.getDiagnosisRecordDetailByRecordNo(dto);
    }

    /**
     * 医生工作台
     * 装载数据：指定医生的患者诊断记录分页数据
     * */
    @PostMapping("/getDiagnosisRecordPagerDataBySearch")
    public Response getDiagnosisRecordPagerDataBySearch(@RequestBody DoctorDiagnosisRecordQuery query){
        return diagnosisRecordService.getDiagnosisRecordPagerDataBySearch(query);
    }



    /**
     * 医生工作台
     * 根据患者档案id查询患者基础信息
     * */
    @PostMapping("/getPatientMasterAndRecordListDataById")
    public Response getPatientMasterAndRecordListDataById(@RequestBody DoctorDiagnosisRecordAndPatientMasterQuery query){
        return patientMasterService.getPatientMasterAndRecordListDataById(query);
    }

    /**
     * 医生工作台-诊断记录
     * 添加检查项目
     * */
    @PostMapping("/createExamOrderByDoctor")
    public Response createExamOrderByDoctor(@RequestBody ExamOrderRequest request){
        return examOrderService.createExamOrder(request);
    }

    /**
     * 医生工作台-诊断记录
     * 加载检查项目
     */
    @PostMapping("/getExamOrderByVisitId")
    public Response getExamOrderByVisitId(@RequestBody ExamOrderRequest request){
        return examOrderService.getExamOrderByVisitId(request);
    }

    /**
     * 医生工作台-诊断记录
     * 删除检查项目
     */
    @PostMapping("/deleteExamOrderItem")
    public Response deleteExamOrderItem(@RequestBody ExamOrderRequest request){
        return examOrderService.deleteExamOrderItem(request);
    }
}
